package LinkedList;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Objects;

public class Demo1<E> {
    //编写一个方法，接受一个LinkedList作为参数，并检查它是否是一个回文集合(正着读和倒着读都一样，如1->2->3->2->1)。
    private E name;
    private E age;

    public Demo1(E name, E age) {
        this.name = name;
        this.age = age;
    }

    public E getName() {
        return name;
    }

    public void setName(E name) {
        this.name = name;
    }

    public E getAge() {
        return age;
    }

    public void setAge(E age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Demo1{" +
                "name=" + name +
                ", age=" + age +
                '}';
    }

    public static void main(String[] args) {
        LinkedList<String> list = new LinkedList();

        LinkedList<Demo1> linkedList = new LinkedList<>();
        var demo1 = new Demo1("adfef",15);
        System.out.println(linkedList.add(demo1));
        demo1.setName("zhangsan");
        demo1.setAge(22);
        linkedList.forEach(System.out::println);
        list.add("abc");
        list.add("bcd");
        list.add("cde");
        list.add("bcd");
        list.add("abc");
        System.out.println(huiWen(list));
    }
    public static boolean huiWen(LinkedList<String> list){
        while (list.size() <= 1){
            if (Objects.equals(list.peekFirst(),list.peekLast())){
                list.removeFirst();
                list.removeLast();
            }else {
                return false;
            }
        }
        return true;
    }
}
